package com.pony.iphone.controller;

import com.pony.iphone.dto.DingTalkCallbackRequest;
import com.pony.iphone.utils.ding.DingTalkUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author pony
 * @version 1.0
 * @description: 钉钉机器人回调方法
 * @create 2025/11/6 11:38
 */
@Slf4j
@RestController
@RequestMapping("/dingtalk")
public class DingTalkController {
    @Autowired
    private DingTalkUtil dingTalkUtil;

//    /**
//     * 接收钉钉机器人回调消息
//     */
//    @PostMapping("/callback")
//    public Map<String, String> handleCallback(@RequestBody DingTalkCallbackRequest request) {
//        log.info("收到钉钉回调: {}", request);
//
//        // 验证签名等安全处理...
//
//        // 根据用户消息内容回复
//        String userMessage = request.getText().getContent();
//        String response = processUserMessage(userMessage, request.getSenderId());
//
//        return Map.of(
//                "msgtype", "text",
//                "text", Map.of("content", response)
//        );
//    }

    private String processUserMessage(String userMessage, String senderId) {
        switch (userMessage.trim()) {
            case "菜单":
                return "请选择功能：\n1. 查询题库\n2. 系统状态\n3. 使用帮助";

            case "1":
            case "查询题库":
                return "题库统计：\n- 总题目数：1000\n- 今日新增：5\n- 待审核：3";

            case "2":
            case "系统状态":
                return "系统状态：\n✅ 服务正常\n✅ 数据库正常\n🟡 缓存服务负载较高";

            case "3":
            case "帮助":
                return "可用命令：\n- 菜单：显示功能菜单\n- 状态：查看系统状态\n- 帮助：显示帮助信息";

            default:
                return "抱歉，我不理解您的指令。请输入「菜单」查看可用功能。";
        }
    }
}
